package com.itbaizhan.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class MyAspect {
    @Pointcut("execution(* com.itbaizhan.dao.UserDao.*(..))")
    public void pointCut(){

    }

    @AfterReturning("pointCut()")
    public void afterReturn(JoinPoint joinPoint){
        System.out.println(joinPoint.getSignature().getName());
        System.out.println("ok");
    }

    public void before(){
        System.out.println("before");
    }

    public void finalMethod(){
        System.out.println("final");
    }

    public void wrong(Exception exception){
        System.out.println("an exception occurred");
    }

    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("before around");
        Object o = proceedingJoinPoint.proceed();
        System.out.println("after around");
        return o;
    }
}
